// 对象扁平化
function flatten(obj) {
  const result = {};
  function flat(obj, prefix) {
    for (let key in obj) {
      if (obj.hasOwnProperty(key)) {
        const value = obj[key];
        if (typeof value === 'object') {
          flat(value, prefix + key + '.');
        } else {
          result[prefix + key] = value;
        }
      }
    }
  }
  flat(obj, '');
  return result;
}
// 测试
const obj = {
  a: 1,
  b: {
    c: 2,
    d: {
      e: 3,
    }
  }
}
console.log(flatten(obj));
